﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdThumbnailImage : IDisposable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdThumbnailImage(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdThumbnailImage obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdThumbnailImage()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdThumbnailImage(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public OdBinaryData header
		{
			get
			{
				IntPtr intPtr = TD_DbPINVOKE.OdThumbnailImage_header_get(this.swigCPtr);
				OdBinaryData result = (intPtr == IntPtr.Zero) ? null : new OdBinaryData(intPtr, false);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				return result;
			}
			set
			{
				TD_DbPINVOKE.OdThumbnailImage_header_set(this.swigCPtr, OdBinaryData.getCPtr(value));
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
		}

		public OdBinaryData bmp
		{
			get
			{
				IntPtr intPtr = TD_DbPINVOKE.OdThumbnailImage_bmp_get(this.swigCPtr);
				OdBinaryData result = (intPtr == IntPtr.Zero) ? null : new OdBinaryData(intPtr, false);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				return result;
			}
			set
			{
				TD_DbPINVOKE.OdThumbnailImage_bmp_set(this.swigCPtr, OdBinaryData.getCPtr(value));
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
		}

		public OdBinaryData wmf
		{
			get
			{
				IntPtr intPtr = TD_DbPINVOKE.OdThumbnailImage_wmf_get(this.swigCPtr);
				OdBinaryData result = (intPtr == IntPtr.Zero) ? null : new OdBinaryData(intPtr, false);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				return result;
			}
			set
			{
				TD_DbPINVOKE.OdThumbnailImage_wmf_set(this.swigCPtr, OdBinaryData.getCPtr(value));
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
		}

		public OdBinaryData png
		{
			get
			{
				IntPtr intPtr = TD_DbPINVOKE.OdThumbnailImage_png_get(this.swigCPtr);
				OdBinaryData result = (intPtr == IntPtr.Zero) ? null : new OdBinaryData(intPtr, false);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				return result;
			}
			set
			{
				TD_DbPINVOKE.OdThumbnailImage_png_set(this.swigCPtr, OdBinaryData.getCPtr(value));
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
		}

		public bool hasHeader()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_hasHeader(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool hasBmp()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_hasBmp(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool hasWmf()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_hasWmf(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool hasPng()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_hasPng(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public int getNumEntries()
		{
			int result = TD_DbPINVOKE.OdThumbnailImage_getNumEntries(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool convPngToBmp()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_convPngToBmp(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool convBmpToPng()
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_convBmpToPng(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void setImageData(IntPtr pData, uint dataLengt)
		{
			TD_DbPINVOKE.OdThumbnailImage_setImageData(this.swigCPtr, pData, dataLengt);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public IntPtr getImageData(out uint dataLengt)
		{
			IntPtr result = TD_DbPINVOKE.OdThumbnailImage_getImageData(this.swigCPtr, out dataLengt);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool setRasterImage(OdGiRasterImage image)
		{
			bool result = TD_DbPINVOKE.OdThumbnailImage_setRasterImage(this.swigCPtr, OdGiRasterImage.getCPtr(image));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdGiRasterImage getRasterImage()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdThumbnailImage_getRasterImage(this.swigCPtr);
			OdGiRasterImage result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdThumbnailImage() : this(TD_DbPINVOKE.new_OdThumbnailImage(), true)
		{
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;
	}
}
